<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>

<body>
    <div id="app">
        <p>{{num1}}</p>
        <partchild1 :count="count" :fn="addCount" @transfer="getvalue"></partchild1>
    </div>
</body>

</html>
<script>
    // 解决单项数据流的2种方式
    // 传递父组件中的方法
    // 使用$parent
    const app = Vue.createApp({
        data() {
            return {
                count: 100,
                num1: 0
            }
        },
        methods: {
            addCount() {
                this.count++
            },
            getvalue(m) {
                this.num1 = m
            }
        },
        components: {
            partchild1: {
                template: `<div @click='editCountFn' >我是局部组件--{{count}}</div>`,
                props: ['count', 'fn'],
                data() {
                    return {
                        num: 10
                    }
                },
                methods: {
                    editCountFn() {
                        // this.count++
                        // this.fn()
                        this.$parent.addCount()
                        this.$emit('transfer', this.num)
                    }
                }
            }
        }
    }).mount('#app')

</script>